package org.choerodon.address.infra.mapper;


import org.apache.ibatis.annotations.Param;
import org.choerodon.address.domain.AreaVo;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;

/**
 * 地址表Mapper
 *
 * @author jiu.yang@hand-china.com 2021-12-06 11:38:11
 */
@Component
public interface AddressMapper extends BaseMapper<AreaVo> {


    /**
     * 查询下层子孙节点递归结构通过节点主键
     *
     * @param id 节点主建
     * @return
     * @throws RuntimeException exception description
     * @version 1.0
     */
    List<AreaVo> queryById(@Param(value = "id") Long id);


    /**
     * 查询下所有右节点大于插入点右节点
     *
     * @param rightNode 右节点
     * @return
     * @throws RuntimeException exception description
     * @version 1.0
     */
    List<AreaVo> queryRightNode(@Param(value = "rightNode") Integer rightNode);

    /**
     * 查询下所有左节点大于插入点左节点
     *
     * @param rightNode 右节点
     * @return
     * @throws RuntimeException exception description
     * @version 1.0
     */
    List<AreaVo> queryLeftNode(@Param(value = "rightNode") Integer rightNode);


    /**
     * 查询删除节点信息
     *
     * @param addressCode 地址编码
     * @return
     * @throws RuntimeException exception description
     * @version 1.0
     */
    AreaVo queryDeleteNode(@Param(value = "addressCode") String addressCode);

    /**
     * 删除节点
     *
     * @param rightNode 右节点
     * @param leftNode  左节点
     * @return
     * @throws RuntimeException exception description
     * @version 1.0
     */
    void deleteNode(@Param(value = "rightNode") Integer rightNode,
                    @Param(value = "leftNode") Integer leftNode);


    /**
     * 更新右节点
     *
     * @param rightNode 右节点
     * @param leftNode  左节点
     * @param diff  差
     * @return
     * @throws RuntimeException exception description
     * @version 1.0
     */
    void updateRight(@Param(value = "rightNode") Integer rightNode,
                     @Param(value = "leftNode") Integer leftNode,
                     @Param(value = "diff") Integer diff);


    /**
     * 更新左节点
     *
     * @param rightNode 右节点
     * @param leftNode  左节点
     * @param diff  差
     * @return
     * @throws RuntimeException exception description
     * @version 1.0
     */
    void updateLeft(@Param(value = "rightNode") Integer rightNode,
                    @Param(value = "leftNode") Integer leftNode,
                    @Param(value = "diff") Integer diff);
}
